package com.ruoyi.system.controller;

import com.alibaba.dashscope.app.Application;
import com.alibaba.dashscope.app.ApplicationParam;
import com.alibaba.dashscope.app.ApplicationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: CustomerController
 * @Author: muhaoyang1
 * @Date: 2025/2/25 21:39
 * @Comment:
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @PostMapping
    public AjaxResult answer(@RequestParam("message") String message) throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                // 若没有配置环境变量，可用百炼API Key将下行替换为：.apiKey("sk-xxx")。但不建议在生产环境中直接将API Key硬编码到代码中，以减少API Key泄露风险。
                .apiKey("sk-cc5d5a85ca5d453b8415d04c02205fc6")
                .appId("483bd651d3714d3fa386d75ea5edbe6c")
                .prompt(message)
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        return AjaxResult.success(result.getOutput().getText());
    }

}
